package leetcode.code1975;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public long maxMatrixSum(int[][] matrix) {
		long sum = 0, min = Integer.MAX_VALUE, cnt = 0;
		int m = matrix.length, n = matrix[0].length;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = matrix[i][j];
				long curAbs = Math.abs(cur);
				sum += curAbs;
				min = Math.min(min, curAbs);
				cnt += cur < 0 ? 1 : 0;
			}
		}
		return (cnt & 1) == 0 ? sum : sum - (min << 1);
	}

	@Override
	public void debug4() {
		H.compare(4, this.maxMatrixSum(H.str2array1("[[1,-1],[-1,1]]")));
		H.compare(16, this.maxMatrixSum(H.str2array1("[[1,2,3],[-1,-2,-3],[1,2,3]]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
